package web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import web.servlet.dto.DtoFactory;
import data.model.User;

public class LogoutServlet extends AbstractJsonCapableServlet {

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final User user = dataLayer.findUserByEmail(request.getParameter("email"));
        user.setCurrentAccessToken(null);
        dataLayer.updateObject(user);

        jsonHandler.writeAsJson(DtoFactory.createMessage("You have signed out successfully"), response);
    }

}
